package com.jt.controller;

import com.jt.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;


@Controller
public class UserController {
    @RequestMapping("/user")
//    public ModelAndView toUser(){
//        ModelAndView mav=new ModelAndView();
//        //设置页面
//        mav.setViewName("user");
//        //设置属性
//        mav.addObject("id","10086");
//        mav.addObject("name","哲♂学的气息");
//        return mav;
//    }
    public String user(Model m){
        m.addAttribute("id","11222");
        m.addAttribute("name", "手艺十三香");
        return "user";
    }
   /*
        请求路径：localhost:8089/adduser\
        传递参数：传了两参数
   */
    @RequestMapping("/addUser")
//    public String adduser(HttpServletRequest request){
//        Integer a=Integer.parseInt(request.getParameter("id"));
//        String b=request.getParameter("name");
//        System.out.println("id"+a+"\nname"+b);
//        return "success";
//    }
    public String adduser(User user){
        System.out.println("id"+user.getId()+":name"+user.getName()+ Arrays.toString(user.getHobby()));
        return "success";
    }
    @RequestMapping("/user1")
    public String user1(String name){
        return "forward:/dog";
    }
    @RequestMapping("/dog")
    public String dog(String name,Model model){
        System.out.println(name);
        model.addAttribute("name", name);
        return "dog";
    }
    @RequestMapping("/hello1")
    public String hello(){
        return "user";
    }
    @RequestMapping("/user2/{id}/{name}")
    public String user2(@PathVariable Integer id,@PathVariable String name){
        System.out.println("接受参数"+id+"|"+name);
        return "success";
    }
}
